package com.ruitu.mall_98_1.product.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.beanu.arad.base.BaseFragment;
import com.beanu.arad.base.my_base.Config;
import com.ruitu.mall_98_1.R;
import com.ruitu.mall_98_1.product.activity.ShopDetailActivity;

public class ShopDetail2Fragment extends BaseFragment {
    protected WebView webview;//
    protected TextView tv_copyright, tv_phone, tv_addr, tv_support;

    public static ShopDetail2Fragment newInstance() {
        Bundle args = new Bundle();
        ShopDetail2Fragment fragment = new ShopDetail2Fragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.pro_shop_detail_url, container, false);

        tv_copyright = v.findViewById(R.id.tv_copyright);
        tv_phone = v.findViewById(R.id.tv_phone);
        tv_addr = v.findViewById(R.id.tv_addr);
        tv_support = v.findViewById(R.id.tv_support);
        webview = v.findViewById(R.id.webview);

        initWebview(Config.URL + "company/goAbout?shopId=" + ((ShopDetailActivity) getActivity()).company.getId());
        ((ShopDetailActivity) getActivity()).setShopBottom(tv_copyright, tv_phone, tv_addr, tv_support);

        return v;
    }

    protected void initWebview(String url) {
        webview.getSettings().setJavaScriptEnabled(true);//开启js的支持
        //自适应屏幕
        webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webview.getSettings().setLoadWithOverviewMode(true);
        webview.setHorizontalScrollBarEnabled(false);//水平不显示
        webview.setVerticalScrollBarEnabled(false); //垂直不显示
        webview.setWebViewClient(new WebViewClient() { //调用自身，不调用系统浏览器
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (TextUtils.isEmpty(url)) {
                } else {
                    if (url.startsWith("tmall://")) {

                    } else {
                        view.loadUrl(url);
                    }
                }
                return true;
            }
        });
        webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                // Activity和Webview根据加载程度决定进度条的进度大小
                // 当加载到100%的时候 进度条自动消失
                if (progress == 100) {
                }
            }
        });
        webview.loadUrl(url);
    }
}